﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;

using Ko2.DB;

public partial class Reports_Verify_TradeProgressOnline_Verify : System.Web.UI.Page
{

    DataTable tbl = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime dtNow = DateTime.Now;
        dtNow = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day);
        dateTime.SelectedDateTime = dtNow;
    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        tbl = new DataTable();
        MySql my = new MySql();
        Exception err = my.GetTradeOnline(ref tbl, dateTime.SelectedDateTime);
        if (err == null)
        {
            gv.DataSource = tbl;
            tbl.Columns.Add("Axapta");
            tbl.Columns.Add("Разница");
            AxaptaValidate();
            gv.DataBind();
        }

    }

    protected void AxaptaValidate()
    {
        Ax ax = new Ax();
        foreach (DataRow r in tbl.Rows)
        {
            string ShopName = r[0].ToString();
            Decimal app10Total = 0;
            if (r["Итого"] != DBNull.Value)
                app10Total = Convert.ToDecimal(r["Итого"]);

            DataTable tblTmp = new DataTable();
            Decimal value = 0;
            if (ax.GetTradeProgress(ref tblTmp, dateTime.SelectedDateTime, ShopName) == null)
            {
                if (tblTmp != null && tblTmp.Rows.Count > 0)
                {
                    if (tblTmp.Rows[0][1] != DBNull.Value)
                    {
                        value = (Decimal)tblTmp.Rows[0][1];
                    }
                }
            }
            r["Axapta"] = value;
            r["Разница"] = app10Total - value;
        }
    }

    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            string str = e.Row.Cells[6].Text;
            str = HttpUtility.HtmlDecode(str); str = str.Trim();
            Decimal value = 0;
            if (!String.IsNullOrEmpty(str))
                value = Convert.ToDecimal(str);
            str = ((int)value).ToString("C").Replace("р.", "");
            if (str.Length > 3)
                str = str.Substring(0, str.Length - 3);
            e.Row.Cells[6].Text = str;
            e.Row.Cells[6].ForeColor = Color.Gray;

            str = e.Row.Cells[7].Text;
            str = HttpUtility.HtmlDecode(str); str = str.Trim();
            value = 0;
            if (!String.IsNullOrEmpty(str))
                value = Convert.ToDecimal(str);
            str = ((int)value).ToString("C").Replace("р.", "");
            if (str.Length > 3)
                str = str.Substring(0, str.Length - 3);
            e.Row.Cells[7].Text = str;
            e.Row.Cells[7].ForeColor = Color.DarkBlue;

            str = e.Row.Cells[8].Text;
            str = HttpUtility.HtmlDecode(str); str = str.Trim();
            value = 0;
            if (!String.IsNullOrEmpty(str))
                value = Convert.ToDecimal(str);
            str = ((int)value).ToString("C").Replace("р.", "");
            if (str.Length > 3)
                str = str.Substring(0, str.Length - 3);
            e.Row.Cells[8].Text = str;
            e.Row.Cells[8].ForeColor = Color.Fuchsia;

        }
    }

}